unit FlashTaskBar;

interface

uses
  Classes, sysutils, Windows, Forms;

Type
  TFlashTaskBar = class
    private
      FForm: TForm;
      FFlash: Boolean;
    public
      procedure Execute;
      procedure Stop;

      constructor Create;
      property Form:TForm read FForm Write FForm;

  end;

implementation

{ TFlashTaskBar }

{
FLASHW_STOP = 0      // Stop flashing
FLASHW_CAPTION = 1   // Flash the window caption
FLASHW_TRAY = 2      // Flash the taskbar button
FLASHW_ALL = 3       // Flash both the window caption and taskbar button
FLASHW_TIMER = 4     // Flash continuously, until the FLASHW_STOP flag is set
FLASHW_TIMERNOFG = 5 // Flash continuously until the window
                     // comes to the foreground
}
constructor TFlashTaskBar.Create;
begin
  FFlash := False;
end;

procedure TFlashTaskBar.Execute;
var
  FWI: TFlashWInfo;
begin
  if FFlash then Exit;
  if (GetForeGroundWindow() = FForm.Handle) then Exit;
  if (FForm.WindowState = wsNormal) then Exit;

  FWI.cbSize  := SizeOf(FLASHWINFO);
  FWI.hwnd    := FForm.Handle;
  FWI.dwFlags := FLASHW_ALL or FLASHW_TIMER;
  FWI.uCount  := 30;
  FWI.dwTimeout := 0;
  FlashWindowEx(FWI);

  FFlash := True;
end;

procedure TFlashTaskBar.Stop;
var
  FWinfo: TFlashWInfo;
begin
  if not FFlash then Exit;

  FWinfo.cbSize  := SizeOf(FLASHWINFO);
  FWinfo.hwnd    := FForm.Handle;
  FWinfo.dwFlags := FLASHW_STOP;
  FWinfo.ucount  := 0;
  FWinfo.dwtimeout := 0;
  FlashWindowEx(FWinfo);

  FFlash := False;
end;

end.
